package com.sixkey.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sixkey.annotation.OperationLog;
import com.sixkey.entity.Evaluation;
import com.sixkey.entity.User;
import com.sixkey.entity.vo.EvaluationVo;
import com.sixkey.entity.vo.UserVo;
import com.sixkey.response.Response;
import com.sixkey.service.IEvaluationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * ClassName: ApiEvaluationController
 * Package: com.sixkey.controller.api
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2023/10/17 - 23:59
 * @Version: v1.0
 */

/**
 * 用户评价
 */
@Slf4j
@Validated
@CrossOrigin
@RestController
@RequestMapping("/evaluation")
@RequiredArgsConstructor
public class EvaluationController {

    private final IEvaluationService evaluationService;

    /**
     * 后台分页查询用户评价
     * @param
     * @return
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
    public Response list(@PathVariable("pageNo") Integer pageNo,
                         @PathVariable("pageSize") Integer pageSize,
                         EvaluationVo evaluationVo){
        log.info("查询用户评价请求进来~~~~");
        Page<Evaluation> list = evaluationService.queryList(pageNo,pageSize,evaluationVo);
        return Response.success(list);
    }

    /**
     * 用户评价保存
     * @param evaluation
     * @return
     */
    @PostMapping("/save")
    public Response save(@RequestBody @Valid Evaluation evaluation){
        log.info("用户评价保存请求进来~~~~");
        evaluationService.save(evaluation);
        return Response.success();
    }

    /**
     * 用户评价修改
     * @param evaluation
     * @return
     */
    @OperationLog(value = "用户评价修改")
    @PutMapping("/update")
    public Response update(@RequestBody @Valid Evaluation evaluation){
        log.info("用户评价修改请求进来~~~~");
        evaluationService.updateById(evaluation);
        return Response.success();
    }

    /**
     * 用户评价修改
     * @param
     * @return
     */
    @GetMapping("/echo/{id}")
    public Response getEvaluationById(@PathVariable("id") Integer id){
        log.info("用户评价修改请求进来~~~~");
        Evaluation evaluation = evaluationService.getById(id);
        return Response.success(evaluation);
    }

    /**
     * 用户评价删除
     * @param
     * @return
     */
    @OperationLog(value = "用户评价删除")
    @DeleteMapping("/remove/{id}")
    public Response remove(@PathVariable("id") List<Integer> id){
        log.info("用户评价删除请求进来~~~~");
        evaluationService.removeBatchByIds(id);
        return Response.success();
    }
}
